package com.cn.wanxi.servlet.back.nav;

import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/back/nav/add")
public class NavAddServlet extends HttpServlet {
    INavService navService = new NavServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        NavModel nav = new NavModel();
        nav.setTitle(req.getParameter("title"));
        nav.setHref(req.getParameter("href"));
        nav.setCreate_time(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date().getTime()));
        int result = navService.addNav(nav);
        resp.getWriter().print(result);
    }
}
